package com.ccl.iot.views;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.AttributeSet;
import android.widget.Button;

public class CustomButton extends Button {

	private Bitmap mBitmap1, mBitmap2;
	private Point mP1, mP2;
	private Paint mPaint;
	private boolean mIsCanvasDot = false;

	public CustomButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	public CustomButton(Context context, AttributeSet attrs) {
		this(context, attrs, android.R.attr.buttonStyle);
	}

	public CustomButton(Context context) {
		this(context, null);
	}

	private void init() {
		mPaint = new Paint();
		mPaint.setAntiAlias(true);
		mPaint.setFilterBitmap(true);
	}

	public void setBitmap1(Bitmap b, Point p) {
		mBitmap1 = b;
		mP1 = p;
		invalidate();
	}
	
	public void setBitmap2(Bitmap b, Point p){
		mBitmap2 = b;
		mP2 = p;
		invalidate();
	}
	
	public void setCanvasDot(boolean isCanvas){
		mIsCanvasDot = isCanvas;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		if (mBitmap1 != null) {
			canvas.drawBitmap(mBitmap1, mP1.x, mP1.y, mPaint);
		}
		
		if (mBitmap2 != null) {
			canvas.drawBitmap(mBitmap2, mP2.x, mP2.y, mPaint);
		}
		
		if(mIsCanvasDot){
			mPaint.setColor(Color.RED);
			canvas.drawCircle(getWidth()-20, 20, 8, mPaint);
		}
	}

}
